<?php
    $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'child-grid',
    'dataProvider'=>$child_model->search($parentID),
    'cssFile' => Util::themeUrl() . '/css/gridview.css',
	'htmlOptions'=>array('class'=>'grid-view clear'),
    'filter'=>$child_model,
    'columns'=>array(
		array(
			'header' =>  'No.',
			'value' => '$row + Util::getPaggingIndex()',
			'htmlOptions' => array(
				'style' => 'width:25px; text-align:center'
			)
		),
		array(
			'class' => 'CCheckBoxColumn',
			'selectableRows' => 2,
			'id' => 'chk',
			'value' => '$data->id',
		),
		array(
		'name'	=>'name',
		'type'	=>'raw',
		'value'	=>'Util::markSearch($data,"name", Util::getUserComment($data))',
		'htmlOptions' => array(
				'style' => 'width:150px;')
		),
		array(
		'name'	=>'email',
		'type'	=>'raw',
		'value'	=>'Util::markSearch($data,"email", ($data->user_id != "" ? $data->user->email : $data->email))',
		'htmlOptions' => array(
				'style' => 'width:100px;')
		),
		array(
		'name'	=>'content',
		'type'	=>'raw',
		'value'	=>'Util::markSearch($data,"content")',
		),
		array(
		'name'			=>'status',
	  	'type' 			=> 'raw',
	  	'value' 		=> 'CHtml::link(CHtml::image(Util::themeUrl(). "/images/" . (($data->status==STATUS_ACTIVE)?"tick_circle.png":"cross_circle.png")), array("update_status", "id"=>$data->id, "returnUrl" => "index"), array("class" => "update-status"))',
		'filter' 		=> Util::itemAlias('Status'),
	  	'htmlOptions' 	=> array(
				'style' => 'width:70px;text-align:center',
			)
		),
		array(
		'name'	=>'create_at',
		'type'	=>'raw',
		'value'	=>'Util::markSearch($data,"create_at")',
		'htmlOptions' => array(
				'style' => 'width:70px;')
		),
		array(
			'class'=>'CButtonColumn',
			'template' => '{update} {delete}',
			'buttons'=>array(
				'update' => array (
					'label'=>'Phản hồi',
					'imageUrl' => Util::themeUrl() . '/images/add2.png',
					'url'=>'Yii::app()->createUrl("comments/comments/create/", array("id"=>$data->id))',
				),
			),
			'htmlOptions' => array(
				'style' => 'width:50px;text-align:center',
			)
		),
	),
));
?>

<script  type="text/javascript">
	$(document).ready(function() {
		$. bind_data = function(){
			$("#child-grid a.delete").click(function() {
				$.ajax({
					type: "POST",
					url: url,
					success: function(data) {
						alert('Dữ liệu xóa thành công.');
						$.fn.yiiGridView.update('child-grid');
					} //success
				});//ajax
				return false;
			});

			$("#child-grid a.update").live('click', function() {
				var url = $(this).attr('href') + '?ajax=true';
				$.fancybox.open({
					href : url,
					type : 'iframe',
					minWidth: 250,
					maxWidth: 400,
					width: 400,
					afterClose: function(){
						$.fn.yiiGridView.update('child-grid');
					}
				});
				return false;
			});
		}

		// bind data
		$. bind_data();
	});
</script>